package czopyk.tests;

import cern.colt.Arrays;

import com.espertech.esper.client.Configuration;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;

public class EsperTest1 {

	private EPServiceProvider epService;

	public EsperTest1() {
		super();
		Configuration config = new Configuration();
		config.addEventTypeAutoName("pl.czopyk.model.analysis");
		epService = EPServiceProviderManager.getDefaultProvider(config);

		EPStatement statement;
		statement = epService
				.getEPAdministrator()
				.createEPL(
						"select time from RequestCompleteEvent.win:length_batch(2) output snapshot every 1 events order by time asc");
		
		statement.setSubscriber(new Object() {
			/*
			public void update(RequestCompleteEvent[] row, RequestCompleteEvent[] out) {
				System.out.println("times: " + row.length);
				//double val = Double.valueOf(e.get("time").toString());
				System.out.println(Arrays.toString(row));
			}
			*/
			public void update(double[] insertStream, double[] removeStream) {
				System.out.println("times: " + insertStream.length + " " + (removeStream == null));
				//double val = Double.valueOf(e.get("time").toString());
				System.out.println(Arrays.toString(insertStream));
			}
			/*
			public void update(double c) {
				System.out.println(c);
			}
			*/
		});
		/*
		.addListener(new UpdateListener() {
			public void update(EventBean[] arg0, EventBean[] arg1) {
				EventBean e = arg0[0];
				System.out.println("arg0: " + arg0.length);
				double val = Double.valueOf(e.get("time").toString());
				System.out.println(val);
			}
		});
*/
		for (Integer i : new Integer[] { 1, 2, 3, 2, 1}) {
			czopyk.model.analysis.RequestCompleteEvent r = new czopyk.model.analysis.RequestCompleteEvent(null, i, i);
			epService.getEPRuntime().sendEvent(r);
		}

	}

	public static void main(String[] args) throws Exception {
		new EsperTest1();
	}
}
